// my_other/duihuanjl/duihuanjl.js
let app = getApp()
let yuming = app.globalData.yuming;
var shuzong = []
var shu = []
const request = require('../../config/request');
Page({

  /**
   * 页面的初始数据
   */
  ...request,
  data: {
    yuming: yuming,
    title: '兑换记录',
    huan: ['已兑换', '已领取'],
    page: 1,
    gongwu: false,
    currtab: 0,
    list: [],
    order_status: -1
  },
  // tab切换
  qies(e) {
    shuzong = []
    shu = []
    var index = e.currentTarget.dataset.currtab
    this.setData({
      list: [],
      currtab: index,
      page: 1,
      gongwu: false,
    })
    if (this.data.currtab == 0) {
      this.setData({
        order_status: -1
      })
    } else {
      this.setData({
        order_status: 1
      })
    }
    this.getList();
  }, // 查看更多
  lookmore() {
    shuzong = this.data.list
    this.setData({
      page: (this.data.page) + 1
    })
    this.getList();
  },
  getList() {
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    let that = this;
    this.myRequest(yuming + 'shop/scan_pay_orderlist', {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page,
      order_status: that.data.order_status,
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading();
        shu = res.data.data
        if (that.data.page != 1) {
          if (shu.length != 10) {
            that.setData({
              gongwu: true
            })
          }
        }
        this.setData({
          list: shuzong.concat(shu), //商品列表
        })
      }
    })
  },
  backs() {
    // wx.navigateTo({
    //   url: '/my_dian/dui/dui',
    // })
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5
    })
    this.getList();
  },
  xq(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/my_dian/spxq/spxq?id=' + id,
    })
  },
  shengyu() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})